package com.woniuxy.oldmanapi.mapper;

import com.woniuxy.oldmanapi.entity.Card;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.woniuxy.oldmanapi.vo.CardVo;
import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.common.Mapper;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface CardMapper extends Mapper<Card> {
    @Select("select * from card where number=#{cardNumber}")
    Card selectByCardId(String cardNumber);

    @Update("update card set balance=balance-#{pay} where number=#{num}")
    void updateMoneyByNumAndpay(@Param("num") String cardNumber, @Param("pay") BigDecimal rechargePay);

    List<com.woniuxy.oldmanapi.cvo.CardVo> selectAllvoByCard(String name);

    List<CardVo> selectCardByCons(@Param("balanceStatus") Integer balanceStatus, @Param("status") Integer status, @Param("name") String name);

    @Select("select * from card where older_id=#{id}")
    List<Card> selectCardById(int id);

    @Update("update card set status=4 ,balance=0 where id=#{id}")
    void logout(Integer id);

    @Update("update card set status = 2 where id =#{id}")
    void guashi(int id);

    @Update("update card set status = 3 where id =#{id}")
    void dongjie(int id);

    @Update("update card set status = 4,balance=0 where id =#{id}")
    void zhuxiao(int id);

    @Update("update card set status = 1 where id =#{id}")
    void jiegua(int id);

    @Select("select max(id) from card")
    int selectMaxId();

    @Update("update card set balance = balance+#{num} where id =#{cardId}")
    void updateBalance(@Param("num") Long num, @Param("cardId") Integer cardId);

    CardVo selectOneById(int id);

    @Update("update card set balance=balance+#{pay} where number=#{num}")
    void addMoneyByNumAndpay(@Param("num") String cardNumber, @Param("pay") BigDecimal rechargePay);

    @Select("select id from card where number = #{value}")
    Integer selectByNumber(String number);
}
